﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using Common.Logging;
using Jackie.Utility.Notify.Services;

namespace Jackie.Utility.Notify.ServiceServer
{
    partial class NotifyServerService : ServiceBase
    {
        private ILog logger;
        private ServiceHost publishHost;
        private ServiceHost subscribeHost;

        public NotifyServerService()
        {
            InitializeComponent();

            logger = LogManager.GetLogger(GetType());
            publishHost = new ServiceHost(typeof(PublishService));
            subscribeHost = new ServiceHost(typeof(SubscribeService));
        }

        protected override void OnStart(string[] args)
        {
            logger.Info("start new publish service host and open it!");
            publishHost.Open();
            logger.Info("publish host opened!");

            logger.Info("start new subscribe service host and open it!");
            subscribeHost.Open();
            logger.Info("subscribe host opened!");
        }

        protected override void OnStop()
        {
            logger.Info("start close publish service!");
            publishHost.Close();
            logger.Info("publish service closed!");

            logger.Info("start close subscrible service!");
            subscribeHost.Close();
            logger.Info("subscrible service closed!");
        }
    }
}
